<?php
namespace App\DBs;

use App\DBs\BaseDB;
use Illuminate\Support\Facades\DB;

class MoreFileDB extends BaseDB
{
    /**
     * FILE
     * more 应用ID
     * name 文件名称
     * admin 管理员UID
     * link 链接地址
     */

    protected $table = 'more_file';

    public function __construct()
    {
        parent::__construct();
    }

    /**
     * 列表
     */
    public function getIndex($more)
    {
        $query = DB::table($this->table);
        if ($more) { $query = $query->where('more',$more); }
        $models = $query->orderBy('id','desc')->get();
        $dataArr = array();
        if (!count($models)) {
            return array('code'=>-1, 'msg'=>'没有数据');
        }
        foreach ($models as $model) {
            $createTime = $model->created_at ? date('Y-m-d',$model->created_at) : '未定义';
            $dataArr[] = [
                'id' => $model->id,
                'name' => $model->name,
                'link' => $model->link,
                'createTime' => $createTime,
            ];
        }
        return array('code'=>0, 'msg'=>'操作成功', 'data'=>$dataArr);
    }
}